package com.shop2cn.iapi.sqsellerquery.service;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymatou.iapi.trading.sellerquery2.parameter.resp.SellerExportedPartialOrderInfosResponse;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymttest.utils.EnvSetup;

public class ExportSqOrderInfosCall extends YmatouBaseCall {

	private static String opurl = "api/Seller/exportSqOrderInfos";

	public ExportSqOrderInfosCall() {
//		super(EnvSetup.getSystemUrl("sellerquery2_iapi"), opurl, "POST", "JSON");
		super(EnvSetup.getSystemUrl("sqsellerquery_iapi"), opurl, "POST", "JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).optString("code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public String getBCode() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).optString("BCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).optString("msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	public SellerExportedPartialOrderInfosResponse getExportSellerOrderInfosResponse() {
		SellerExportedPartialOrderInfosResponse response = null;
		try {
			Logger.comment(new JSONObject(getReturnData()).get("data")
					.toString());
			response = (SellerExportedPartialOrderInfosResponse) FormatUtil
					.GSONToObject(new JSONObject(getReturnData()).get("data")
							.toString(),
							SellerExportedPartialOrderInfosResponse.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return response;
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public Object getData() {
		Object Data = null;
		try {
			Data = new JSONObject(getReturnData()).get("data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	/**
	 * 获取Data.SellerExportedPartialOrderInfos
	 * 
	 * @return
	 */
	public JSONArray getSellerExportedPartialOrderInfos() {
		JSONArray sellerExportedPartialOrderInfos = null;
		try {
			sellerExportedPartialOrderInfos = ((JSONObject) getData())
					.getJSONArray("sellerExportedPartialOrderInfos");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return sellerExportedPartialOrderInfos;
	}

	/**
	 * 获取NextPartitionKey
	 * 
	 * @return
	 */
	public String getNextPartitionKey() {
		String nextPartitionKey = null;
		try {
			nextPartitionKey = ((JSONObject) getData())
					.getString("nextPartitionKey");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return nextPartitionKey;
	}
}
